﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using BL.Service;
using BL;
using BL.Entity;
using System.Runtime.Remoting.Channels;

namespace LTO
{
    /// <summary>
    /// Interaction logic for ClientMain.xaml
    /// </summary>
    //static class CustomCommands
    //{
    //    public static RoutedCommand DoStuff = new RoutedCommand();
    //}
    public class ListBoxModel
    {
        public int ID { get; set; }
        public string Value { get; set; }
    }
    public partial class ClientMain : Window
    {
        #region :: Goble Propertie ::
        public List<ListBoxModel> lbShowNumberOver_dataSource = new List<ListBoxModel>();
        public List<ListBoxModel> lbShowOverPriceTeng_dataSource = new List<ListBoxModel>();
        public List<ListBoxModel> lbShowOverPriceTod_dataSource = new List<ListBoxModel>();
        public List<ListBoxModel> lbShowOverResult_dataSource = new List<ListBoxModel>();
        public List<ListBoxModel> lbShowUnderNumber_dataSource = new List<ListBoxModel>();
        public List<ListBoxModel> lbShowUnderPrice_dataSource = new List<ListBoxModel>();
        public List<ListBoxModel> lbShowUnderResult_dataSource = new List<ListBoxModel>();

        public tbl_NumberServer numService = new tbl_NumberServer();
        public List<NumberDTO> numberDTO = new List<NumberDTO>();

        MessageViewer2 msg;
        tbl_NumberServer Numberservice = new tbl_NumberServer();
        tbl_PayService PayService = new tbl_PayService();

        string number;
        string numShow;
        string number1;
        string showWords1;
        string lbResult;
        string result;
        decimal over_price = 0;
        decimal under_price = 0;
        decimal tod_price = 0;

        #endregion

        public ClientMain()
        {
            InitializeComponent();
            System.Threading.Thread sv = new System.Threading.Thread(LoadTotalClient);
            sv.Start();
            this.Title = string.Format("Login : {0}", Gobalsource.UserNameLogin);

            this.Closing += new System.ComponentModel.CancelEventHandler(ClientMain_Closing);
            this.Loaded += new RoutedEventHandler(ClientMain_Loaded);
            HotKey _Hotkey_X = new HotKey(Key.X, KeyModifier.Alt, OnCloseWindows);
            HotKey _HotKey_C = new HotKey(Key.C, KeyModifier.Alt, OnOpenPageSetting);
            HotKey _HotKey_1 = new HotKey(Key.D1, KeyModifier.Alt, OnOpenPage3Over);
            HotKey _HotKey_2 = new HotKey(Key.D2, KeyModifier.Alt, OnOpenPageTod3Over);
            HotKey _HotKey_3 = new HotKey(Key.D3, KeyModifier.Alt, OnOpenPage2Over);
            HotKey _HotKey_4 = new HotKey(Key.D4, KeyModifier.Alt, OnOpenPageTod2Over);
            HotKey _HotKey_5 = new HotKey(Key.D5, KeyModifier.Alt, OnOpenPageRunOver);
            HotKey _HotKey_6 = new HotKey(Key.D6, KeyModifier.Alt, OnOpenPage3Under);
            HotKey _HotKey_7 = new HotKey(Key.D7, KeyModifier.Alt, OnOpenPage2Under);
            HotKey _HotKey_8 = new HotKey(Key.D8, KeyModifier.Alt, OnOpenPageRunUnder);
            HotKey _HotKey_9 = new HotKey(Key.D9, KeyModifier.Alt, OnOpenPageTodGroup);
            //HotKey _HotKey_0 = new HotKey(Key.D0, KeyModifier.Alt, OnOpenPage4P);
            HotKey _HotKey_del = new HotKey(Key.Subtract, KeyModifier.Alt, OnOpenPageTwinFront);
            HotKey _HotKey_equa = new HotKey(Key.OemPlus, KeyModifier.Alt, OnOpenPageTwinTang);
            HotKey _Hotkey_A = new HotKey(Key.A, KeyModifier.Alt, DeleteNumber);
            HotKey _Hotkey_S = new HotKey(Key.S, KeyModifier.Alt, DeleteNumber);
            HotKey _Hotkey_F5 = new HotKey(Key.F5, KeyModifier.None, RefreshNumber);

            Gobalsource.objChatWin.SendMessage("ติดต่อเข้ามา");
        }

        private void LoadTotalClient()
        {

            do
            {
                try
                {
                    lblTotalClient.UpdateControlSafe(new Action(() => lblTotalClient.Content = string.Format("{0}", Gobalsource.TotalClient)));

                }
                catch (Exception)
                {

                }
                System.Threading.Thread.Sleep(1000);
            } while (Gobalsource.IsAppRunning);

        }
        protected void ClientMain_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            Gobalsource.IsAppRunning = false;
        }

        void ClientMain_Loaded(object sender, RoutedEventArgs e)
        {
            newLoadClientMain();
            RefreshNumber();
        }

        private void newLoadClientMain()
        {
            txtOverNumber.Focus();
            GetViewOver1();
            GetViewUnder1();
            RefreshNumber();
        }

        #region :: Other Key Function ::

        private void DeleteNumber(HotKey hotKey)
        {
            DeleteNumber();
        }
        private void RefreshNumber(HotKey hotKey)
        {
            ReloadSceen();
        }
        private void RefreshNumber()
        {
            ReloadSceen();
        }
        private void OnCloseWindows(HotKey hotKey)
        {
            Gobalsource.IsAppRunning = false;

        }
        private void OnOpenPageSetting(HotKey hotKey)
        {
            new PaySetUp2().Show();
        }
        #endregion

        #region :: Textbox event ::
        string orignalTengPrice = string.Empty;
        private void txtOverPriceTeng_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                string txtOver = txtOverNumber.Text;
                string txtTeng = txtOverPriceTeng.Text;
                switch (e.Key)
                {
                    case Key.Add:

                        if (!txtOver.Contains("*") && !txtOver.Contains('/') && !txtOver.Contains('-') && txtOver.Length > 1)
                        {
                            txtOverPriceTod.Focusable = true;
                            txtOverPriceTod.Focus();
                            txtOverPriceTod.SelectAll();
                            if (txtTeng == "")
                            {

                                txtOverPriceTeng.Text = orignalTengPrice;
                            }
                            orignalTengPrice = txtOverPriceTeng.Text;
                            e.Handled = true;
                        }
                        else
                        {
                            System.Media.SystemSounds.Hand.Play();
                            e.Handled = true;
                        }



                        //if (txtOver.Contains('-') || txtOver.Contains('*') || txtOver.Contains('/'))
                        //{

                        //    //txtOverPriceTeng.Text.Replace("+","");
                        //    string txtOPT = txtOverPriceTeng.Text;
                        //    string txtOP = txtOPT.Replace("+", "");
                        //    txtOverPriceTeng.Text = txtOP;
                        //    //txtOverPriceTeng.Text = txtOverPriceTeng.Text.Replace("+", "");
                        //    //txtOverPriceTeng.Text = txtOverPriceTeng.Text.Remove((txtOverPriceTeng.Text.Length -1),1);
                        //    //string txt = txtOverPriceTeng.Text;
                        //    e.Handled = false;
                        //}
                        //else
                        //{
                        //    if (txtTeng == "")
                        //    {
                        //        txtOverPriceTeng.Undo();
                        //    }
                        //    e.Handled = true;
                        //    txtOverPriceTod.Focus();
                        //}


                        break;
                    case Key.Enter:
                        if (txtTeng == "")
                        {

                            txtOverPriceTeng.Text = orignalTengPrice;
                        }
                        orignalTengPrice = txtOverPriceTeng.Text;
                        if (string.IsNullOrEmpty(orignalTengPrice))
                        {
                            throw new Exception("คุณป้อนข้อมูลผืด");

                        }
                        tbl_NumberServer objTblNum = new tbl_NumberServer();
                        number = txtOverNumber.Text;
                        over_price = Decimal.Parse(this.txtOverPriceTeng.Text);
                        tod_price = string.IsNullOrEmpty(this.txtOverPriceTod.Text) ? 0 : Decimal.Parse(this.txtOverPriceTod.Text);

                        lbResult = objTblNum.Addnumber(number, over_price, under_price, tod_price, Gobalsource.UserNameLogin, BL.Enum.NumberType.NumberOverAdd, false);
                        lbShowOverResult_dataSource.Add(new ListBoxModel() { ID = lbShowOverResult.Items.Count + 1, Value = lbResult });

                        lbShowOverResult.ItemsSource = lbShowOverResult_dataSource.OrderByDescending(s => s.ID).ToList(); ;
                        loadOverShow();
                        //  LimitNum = PayService.GetLimit(EnumLocal.NumberType.Over1);
                        GetViewOver1();
                        GetViewUnder1();
                        this.ReloadSceen();
                        result = lbResult;
                        string showWords = objTblNum.showWord(number, over_price, under_price, tod_price, result, 0);

                        Gobalsource.objChatWin.SendMessage(showWords);
                        clearText();
                        break;
                    default:
                        if (e.Key == Key.NumPad0
                                  || e.Key == Key.NumPad1
                                  || e.Key == Key.NumPad2
                                  || e.Key == Key.NumPad3
                                  || e.Key == Key.NumPad4
                                  || e.Key == Key.NumPad5
                                  || e.Key == Key.NumPad6
                                  || e.Key == Key.NumPad7
                                  || e.Key == Key.NumPad8
                                  || e.Key == Key.NumPad9
                        )
                        {
                            e.Handled = false;

                        }
                        else
                        {
                            System.Media.SystemSounds.Hand.Play();
                            e.Handled = true;

                        }
                        break;
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show("ระบุข้อมูลผิด !!!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);

            }

        }
        string orignalOverPrice = string.Empty;

        private void txtOverPriceTod_KeyDown(object sender, KeyEventArgs e)
        {
            tbl_NumberServer objTblNum = new tbl_NumberServer();
            string txtTod = txtOverPriceTod.Text;
            try
            {

                if (e.Key == Key.Enter)
                {
                    if (txtTod == "")
                    {
                        txtOverPriceTod.Undo();
                        txtOverPriceTod.Text = orignalOverPrice;
                    }
                    orignalOverPrice = txtOverPriceTod.Text;
                    if (string.IsNullOrEmpty(orignalOverPrice+orignalTengPrice))
                    {
                        throw new Exception("คุณป้อนข้อมูลผืด");

                    }
                    number = txtOverNumber.Text;
                    over_price = string.IsNullOrEmpty(this.txtOverPriceTeng.Text) ? 0 : Decimal.Parse(this.txtOverPriceTeng.Text);
                    tod_price = string.IsNullOrEmpty(this.txtOverPriceTod.Text) ? 0 : Decimal.Parse(this.txtOverPriceTod.Text);
                    lbResult = objTblNum.Addnumber(number, over_price, under_price, tod_price, Gobalsource.UserNameLogin, BL.Enum.NumberType.NumberOverAdd, false);
                    lbShowOverResult_dataSource.Add(new ListBoxModel() { ID = lbShowOverResult.Items.Count + 1, Value = lbResult });

                    lbShowOverResult.ItemsSource = lbShowOverResult_dataSource.OrderByDescending(s => s.ID).ToList(); ;

                    loadOverShow();
                    GetViewOver1();
                    GetViewUnder1();
                    this.ReloadSceen();

                    result = lbResult;
                    string showWords = objTblNum.showWord(number, over_price, under_price, tod_price, result, 0);

                    Gobalsource.objChatWin.SendMessage(showWords);
                    clearText();
                }



            }
            catch (Exception ex)
            {
                MessageBox.Show("ระบุข้อมูลผิด !!!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                // MessageBox.Show("ไม่สามารถใส่ตัวเลข " + txtOverNumber.Text + " ลงในระบบได้", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void txtOverNumber_KeyDown(object sender, KeyEventArgs e)
        {

            string key = Convert.ToString(e.Key);

            try
            {
                switch (e.Key)
                {
                    case Key.Enter:
                        //  txtOverPriceTeng.Text = string.Empty;

                        if (txtOverNumber.Text.Length < 3 && txtOverNumber.Text.Contains("/"))
                        {
                            txtOverPriceTod.Focusable = false;
                            txtOverPriceTeng.Focus();
                            txtOverPriceTeng.SelectAll();
                        }
                        else if (txtOverNumber.Text.Length == 2 && !txtOverNumber.Text.Contains("/") && !txtOverNumber.Text.Contains("*") && !txtOverNumber.Text.Contains("-"))
                        {
                            txtOverPriceTeng.Focus();
                            txtOverPriceTeng.SelectAll();
                        }
                        else if (txtOverNumber.Text.Length == 3 && !txtOverNumber.Text.Contains("/") && !txtOverNumber.Text.Contains("*"))
                        {
                            if ((txtOverNumber.Text[0] == '-' && txtOverNumber.Text[1] == '-')
                                || (txtOverNumber.Text[0] == '-' && txtOverNumber.Text[2] == '-')
                                || (txtOverNumber.Text[0] != '-' && txtOverNumber.Text[1] == '-' && txtOverNumber.Text[2] != '-')
                                || (txtOverNumber.Text[0] != '-' && txtOverNumber.Text[2] == '-')
                                || (!txtOverNumber.Text.Contains('-')))
                            {
                                txtOverPriceTod.Focusable = true;
                                txtOverPriceTeng.Focus();
                                txtOverPriceTeng.SelectAll();
                            }
                        }

                        else if (txtOverNumber.Text.Length > 3 && !txtOverNumber.Text.Contains("*") && !txtOverNumber.Text.Contains("/") && !txtOverNumber.Text.Contains('-'))
                        {
                            txtOverPriceTod.Focusable = true;
                            txtOverPriceTod.Focus();
                            txtOverPriceTeng.SelectAll();
                        }
                        else if (txtOverNumber.Text.Length > 2 && txtOverNumber.Text[txtOverNumber.Text.Length - 1] == '*' && !txtOverNumber.Text.Contains('-'))
                        {
                            txtOverPriceTod.Focusable = false;
                            txtOverPriceTeng.Focus();
                            txtOverPriceTeng.SelectAll();

                        }
                        else if (txtOverNumber.Text.Length > 1 && txtOverNumber.Text.Contains("/") && !txtOverNumber.Text.Contains('-'))
                        {
                            e.Handled = false;
                        }
                        else if (txtOverNumber.Text.Length == 1 && !txtOverNumber.Text.Contains('-'))
                        {
                            int checknum;
                            if (int.TryParse(txtOverNumber.Text, out checknum))
                            {
                                txtOverPriceTeng.Focus();
                                txtOverPriceTod.Focusable = false;
                                txtOverPriceTeng.SelectAll();
                            }
                        }
                        else
                        {
                            throw new Exception("คุณป้อนข้อมูลผืด");
                        }




                        //{
                        //    txtOverPriceTod.Focus();
                        //}
                        break;
                    case Key.Add:
                        if (txtOverNumber.Text.Length > 1 && !txtOverNumber.Text.Contains("*") && !txtOverNumber.Text.Contains('/') && !txtOverNumber.Text.Contains('-'))
                        {
                            txtOverPriceTod.Focusable = true;
                            txtOverPriceTod.Focus();
                            txtOverPriceTod.SelectAll();
                            //  System.Media.SystemSounds.Hand.Play();
                            e.Handled = true;
                        }
                        else
                        {
                            System.Media.SystemSounds.Hand.Play();
                            e.Handled = true;
                        }
                        break;
                    case Key.Tab:

                        txtUnderNumber.Focus();
                        txtUnderNumber.SelectAll();
                        txtOverNumber.Text = string.Empty;
                        // System.Media.SystemSounds.Hand.Play();
                        e.Handled = true;
                        break;
                    default:
                        string checkFormat = txtOverNumber.Text.Trim();
                        if (checkFormat.Length == 3)
                        {
                            if (checkFormat[0] == '-' && checkFormat[2] == '-')
                            {
                                System.Media.SystemSounds.Hand.Play();
                                e.Handled = true;
                            }
                        }
                        break;
                }

                // objCheck.CheckInputNumber(key);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                //tbError.Text = ex.Message;
            }

        }

        private void txtOverNumber_KeyUp(object sender, KeyEventArgs e)
        {
            string numChcek = txtOverNumber.Text.Replace("---", "!");
          
            if (numChcek.Contains("!"))
            {
                txtOverNumber.Text = string.Empty;
                e.Handled = false;
                System.Media.SystemSounds.Hand.Play();
                MessageBox.Show("ระบุข้อมูลผิด !!!");
                txtOverNumber_MouseLeftButtonUp();
                return;
            }

            if (txtOverNumber.Text.Trim() == "." || txtOverNumber.Text.Trim() == "/" || txtOverNumber.Text.Trim() == "*")
            {
                System.Media.SystemSounds.Hand.Play();
                MessageBox.Show("ระบุข้อมูลผิด !!!");
                txtOverNumber_MouseLeftButtonUp();
                return;
            }
            else if (txtOverNumber.Text.Length > 2 && txtOverNumber.Text.Contains("/"))
            {
                e.Handled = false;
                System.Media.SystemSounds.Hand.Play();
                MessageBox.Show("ระบุข้อมูลผิด !!!");
                txtOverNumber_MouseLeftButtonUp();
                return;
            }
            else if (txtOverNumber.Text.Length < 2 && txtOverNumber.Text.Contains("*"))
            {
                //txtOverNumber.MaxLength = txtOverNumber.Text.Length;
                System.Media.SystemSounds.Hand.Play();
                MessageBox.Show("ระบุข้อมูลผิด !!!");
                txtOverNumber_MouseLeftButtonUp();
                return;
            }

            int indrxOfChar = txtOverNumber.Text.Contains("*") ? txtOverNumber.Text.IndexOf('*') : txtOverNumber.Text.IndexOf('/');
            if (indrxOfChar != -1)
            {
                txtOverNumber.Text = txtOverNumber.Text.Substring(0, indrxOfChar + 1);
                txtOverNumber.Select(txtOverNumber.Text.Length, 0);
            }
        }

        private void txtUnderNumber_KeyUp(object sender, KeyEventArgs e)
        {
            string txtUnder = txtUnderNumber.Text;
            if (txtUnder.Trim() == "." || txtUnder.Trim() == "/" || txtUnder.Trim() == "*")
            {
                txtUnderNumber.Text = string.Empty;
                System.Media.SystemSounds.Hand.Play();
                MessageBox.Show("ระบุข้อมูลผิด !!!");
                txtUnderNumber_MouseLeftButtonUp();
                return;
            }
            else if (txtUnder.Length > 2 && txtUnder.Contains("/"))
            {
                e.Handled = false;
                txtUnderNumber.Text = string.Empty;
                System.Media.SystemSounds.Hand.Play();
                MessageBox.Show("ระบุข้อมูลผิด !!!");
                txtUnderNumber_MouseLeftButtonUp();
                return;
            }
            else if (txtUnder.Length < 4 && txtUnder.Contains("*"))
            {
                txtUnderNumber.Text = string.Empty;
                System.Media.SystemSounds.Hand.Play();
                MessageBox.Show("ระบุข้อมูลผิด !!!");
                txtUnderNumber_MouseLeftButtonUp();
                return;
            }
            else if (txtUnder.Length >= 4 && !txtUnder.Contains("*"))
            {
                txtUnderNumber.Text = string.Empty;
                System.Media.SystemSounds.Hand.Play();
                MessageBox.Show("ระบุข้อมูลผิด !!!");
                txtUnderNumber_MouseLeftButtonUp();
                return;
            }
            else if (txtUnder.Length > 2 && txtUnder.Contains("-"))
            {
                txtUnderNumber.Text = txtUnder.Substring(0, 2);
                System.Media.SystemSounds.Hand.Play();
                MessageBox.Show("ระบุข้อมูลผิด !!!");
                txtUnderNumber_MouseLeftButtonUp();
                return;
            }

            int indrxOfChar = txtUnder.Contains("*") ? txtUnder.IndexOf('*') : txtUnder.IndexOf('/');
            if (indrxOfChar != -1)
            {
                txtUnderNumber.Text = txtUnder.Substring(0, indrxOfChar + 1);
                txtUnderNumber.Select(txtUnder.Length, 0);
            }
        }
        private void txtUnderNumber_KeyDown(object sender, KeyEventArgs e)
        {
            string txtUnder = txtUnderNumber.Text;
            try
            {
                switch (e.Key)
                {
                    case Key.Enter:
                        txtUnderPrice.Text = string.Empty;
                        if (txtUnder.Contains('*'))
                        {
                            string txtCheck = txtUnder.Replace("*", "");
                            if (txtCheck.Length == 2)
                            {
                                System.Media.SystemSounds.Hand.Play();
                                e.Handled = true;
                            }
                            else if (txtCheck.Length == 3)
                            {
                                txtUnderPrice.Focus();
                            }
                        }
                        else if (txtUnder.Length > 2 && txtUnder.Contains("/"))
                        {
                            e.Handled = false;
                        }

                        else if (!string.IsNullOrEmpty(txtUnder))
                        {
                            txtUnderPrice.Focus();
                        }
                        else
                        {
                            throw new Exception("คุณป้อนข้อมูลผืด");
                        }

                        break;
                    case Key.Add:
                        System.Media.SystemSounds.Hand.Play();
                        e.Handled = true;
                        break;
                    case Key.Tab:
                        e.Handled = true;
                        txtUnderNumber.Text = string.Empty;
                        // System.Media.SystemSounds.Hand.Play();
                        txtOverNumber.Focus();
                        txtOverNumber.SelectAll();

                        break;
                    default:
                        break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }

        }

        string orignalUnderPrice = string.Empty;
        private void txtUnderPrice_KeyDown(object sender, KeyEventArgs e)
        {
            string Uprice = txtUnderPrice.Text;
            try
            {
                if (e.Key == Key.Enter)
                {
                    if (Uprice == "")
                    {
                        txtUnderPrice.Text = orignalUnderPrice;
                    }
                    orignalUnderPrice = txtUnderPrice.Text;
                    if (string.IsNullOrEmpty(orignalUnderPrice))
                    {
                        throw new Exception("คุณป้อนข้อมูลผืด");
                        
                    
                    }
                    tbl_NumberServer objTblNum = new tbl_NumberServer();
                    number = txtUnderNumber.Text;
                    under_price = string.IsNullOrEmpty(this.txtUnderPrice.Text) ? 0 : Decimal.Parse(this.txtUnderPrice.Text);

                    lbResult = objTblNum.Addnumber(number, 0, under_price, 0, Gobalsource.UserNameLogin, BL.Enum.NumberType.NumberUnderAdd, false);
                    lbShowUnderResult_dataSource.Add(new ListBoxModel() { ID = lbShowUnderResult.Items.Count + 1, Value = lbResult });

                    lbShowUnderResult.ItemsSource = lbShowUnderResult_dataSource.OrderByDescending(s => s.ID).ToList();

                    loadUnderShow();
                    GetViewOver1();
                    GetViewUnder1();
                    this.ReloadSceen();
                    result = lbResult;
                    string showWords = objTblNum.showWord(number, 0, under_price, 0, result, 0);
                    Gobalsource.objChatWin.SendMessage(showWords);
                    cleatTextUnder();
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);

            }
        }
        #endregion

        #region :: Button Event ::
        private void btnSetting_Click(object sender, RoutedEventArgs e)
        {
            new PaySetUp2().Show();
        }
        private void btnShutdown_Click(object sender, RoutedEventArgs e)
        {
            Gobalsource.IsAppRunning = false;
        }
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            DeleteNumber();
            Button btn = sender as Button;
            if (btn.Name == button1.Name)
            {
                txtOverNumber.Focus();
            }
            else {
                txtUnderNumber.Focus();
            }
        }
        #endregion

        #region :: Hot Key Show Screen ::

        private void OnOpenPage3Over(HotKey hotKey)
        {
            Show3Over();
        }
        private void OnOpenPageTod3Over(HotKey hotKey)
        {
            ShowTod3Over();
        }
        private void OnOpenPage3Under(HotKey hotKey)
        {
            Show3Under();

        }
        private void OnOpenPage2Over(HotKey hotKey)
        {
            Show2Over();
        }
        private void OnOpenPageTod2Over(HotKey hotKey)
        {
            ShowTod2Over();
        }
        private void OnOpenPage2Under(HotKey hotKey)
        {
            Show2Under();
        }
        private void OnOpenPageRunOver(HotKey hotKey)
        {
            Show1Over();
        }
        private void OnOpenPageRunUnder(HotKey hotKey)
        {
            Show1Under();
        }
        private void OnOpenPageTodGroup(HotKey hotKey)
        {
            ShowTodGroup();
        }
        //private void OnOpenPage4P(HotKey hotKey)
        //{
        //    Show4number();
        //}
        private void OnOpenPageTwinFront(HotKey hotKey)
        {
            ShowTwinFornt();
        }
        private void OnOpenPageTwinTang(HotKey hotKey)
        {
            ShowTwinTang();
        }

        #endregion

        #region :: Fucntion Show Sereen ::

        private void Show3Over()
        {
            _listbox showList = new _listbox(EnumLocal.NumberType.Over3);
            showList.Owner = this;
            showList.Show();
            string showWords = "ขอข้อมูลของ 3 ตัวบน";
            Gobalsource.objChatWin.SendMessage(showWords);
        }
        private void Show1Under()
        {
            viewUnder1 showList = new viewUnder1();
            showList.Owner = this;
            showList.Show();
            string showWords = "ขอข้อมูลของ วิ่งล่าง";
            Gobalsource.objChatWin.SendMessage(showWords);
        }
        private void ShowTod3Over()
        {
            _listbox showList = new _listbox(EnumLocal.NumberType.Tod3);
            showList.Owner = this;
            showList.Show();
            string showWords = "ขอข้อมูลของ โต๊ด 3 บน";
            Gobalsource.objChatWin.SendMessage(showWords);
        }
        private void Show3Under()
        {
            _listbox showList = new _listbox(EnumLocal.NumberType.Under3);
            showList.Owner = this;
            showList.Show();
            string showWords = "ขอข้อมูลของ 3 ตัวล่าง";
            Gobalsource.objChatWin.SendMessage(showWords);
        }
        private void Show2Over()
        {
            _listbox showList = new _listbox(EnumLocal.NumberType.Over2);
            showList.Owner = this;
            showList.Show();
            string showWords = "ขอข้อมูลของ 2 ตัวบน";
            Gobalsource.objChatWin.SendMessage(showWords);
        }
        private void ShowTod2Over()
        {
            _listbox showList = new _listbox(EnumLocal.NumberType.Tod2);
            showList.Owner = this;
            showList.Show();
            string showWords = "ขอข้อมูลของ โต๊ด 2 บน";
            Gobalsource.objChatWin.SendMessage(showWords);
        }
        private void Show2Under()
        {
            _listbox showList = new _listbox(EnumLocal.NumberType.Under2);
            showList.Owner = this;
            showList.Show();
            string showWords = "ขอข้อมูลของ 2 ตัวล่าง";
            Gobalsource.objChatWin.SendMessage(showWords);
        }
        private void ShowTwinFornt()
        {
            _listbox showList = new _listbox(EnumLocal.NumberType.TwinFront);
            showList.Owner = this;
            showList.Show();
            string showWords = "ขอข้อมูลของ 2 ตัวบนคู่หน้า";
            Gobalsource.objChatWin.SendMessage(showWords);
        }
        private void ShowTwinTang()
        {
            _listbox showList = new _listbox(EnumLocal.NumberType.TwinStretch);
            showList.Owner = this;
            showList.Show();
            string showWords = "ขอข้อมูลของ 3 ตัวบนคู่ถ่าง";
            Gobalsource.objChatWin.SendMessage(showWords);
        }
        private void Show1Over()
        {
            ViewOver1 showList = new ViewOver1();
            showList.Owner = this;
            showList.Show();
            string showWords = "ขอข้อมูลของ วิ่งบน";
            Gobalsource.objChatWin.SendMessage(showWords);
        }
        //private void Show4number()
        //{
        //    viewFourNumber showList = new viewFourNumber();
        //    showList.Owner = this;
        //    showList.Show();
        //    string showWords = "ขอข้อมูลของ พวง 4 ตัว";
        //    Gobalsource.objChatWin.SendMessage(showWords);
        //}
        private void ShowTodGroup()
        {
            viewTodGroup showList = new viewTodGroup();
            showList.Owner = this;
            showList.Show();
            string showWords = "ขอข้อมูลของ โต๊ดบนหมู่";
            Gobalsource.objChatWin.SendMessage(showWords);
        }

        #endregion

        #region :: Btn Show Screen ::
        private void btnUser_Click(object sender, RoutedEventArgs e)
        {
            new UserSetup().Show();
        }
        private void btn3Over_Click(object sender, RoutedEventArgs e)
        {
            Show3Over();
        }
        private void btnRunUnder_Click(object sender, RoutedEventArgs e)
        {
            Show1Under();

        }
        private void btnTod3Over_Click(object sender, RoutedEventArgs e)
        {
            ShowTod3Over();
        }
        private void btn3Under_Click(object sender, RoutedEventArgs e)
        {
            Show3Under();
        }
        private void btn2Over_Click(object sender, RoutedEventArgs e)
        {
            Show2Over();

        }
        private void btnTod2Over_Click(object sender, RoutedEventArgs e)
        {
            ShowTod2Over();
            //viewNumber.xaml
        }
        private void btn2Under_Click(object sender, RoutedEventArgs e)
        {
            Show2Under();
            //viewNumber.xaml
        }
        private void btnTwinFront_Click(object sender, RoutedEventArgs e)
        {
            ShowTwinFornt();
        }
        private void btnTwinTang_Click(object sender, RoutedEventArgs e)
        {
            ShowTwinTang();
        }
        private void btnRunOver_Click(object sender, RoutedEventArgs e)
        {
            Show1Over();
            // viewOver1_2.xaml
        }
        //private void btn4P_Click(object sender, RoutedEventArgs e)
        //{
        //    Show4number();
        //}
        private void btnGroupTod_Click(object sender, RoutedEventArgs e)
        {
            ShowTodGroup();
        }
        #endregion

        #region :: ListView Event ::
        private void lbShowNumberOver_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {


            lbShowOverPriceTeng.SelectedIndex = lbShowNumberOver.SelectedIndex;
            lbShowOverPriceTod.SelectedIndex = lbShowNumberOver.SelectedIndex;
            lbShowOverResult.SelectedIndex = lbShowNumberOver.SelectedIndex;

        }
        private void lbShowUnderNumber_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ListBox selecttion = (sender as ListBox);
            lbShowUnderPrice.SelectedIndex = selecttion.SelectedIndex;
            lbShowUnderResult.SelectedIndex = selecttion.SelectedIndex;
            lbShowUnderPrice.Focus();
            ClearListboxOver();
        }
        void lbShowNumberOverScroll_ScrollChanged(object sender, ScrollChangedEventArgs e)
        {
            lbShowOverPriceTengScroll.ScrollToVerticalOffset((sender as ScrollViewer).VerticalOffset);
            lbShowOverPriceTodScroll.ScrollToVerticalOffset((sender as ScrollViewer).VerticalOffset);
        }
        void lbShowOverPriceTengScroll_ScrollChanged(object sender, ScrollChangedEventArgs e)
        {
            lbShowNumberOverScroll.ScrollToVerticalOffset((sender as ScrollViewer).VerticalOffset);
            lbShowOverPriceTodScroll.ScrollToVerticalOffset((sender as ScrollViewer).VerticalOffset);
        }
        void lbShowOverPriceTodScroll_ScrollChanged(object sender, ScrollChangedEventArgs e)
        {
            lbShowOverPriceTengScroll.ScrollToVerticalOffset((sender as ScrollViewer).VerticalOffset);
            lbShowNumberOverScroll.ScrollToVerticalOffset((sender as ScrollViewer).VerticalOffset);
        }
        void lbShowOverResult_ScrollChanged(object sender, ScrollChangedEventArgs e)
        {
            lbShowNumberOverScroll.ScrollToVerticalOffset((sender as ScrollViewer).VerticalOffset);
            lbShowOverPriceTengScroll.ScrollToVerticalOffset((sender as ScrollViewer).VerticalOffset);
            lbShowOverPriceTodScroll.ScrollToVerticalOffset((sender as ScrollViewer).VerticalOffset);
        }
        void lbShowUnderResult_ScrollChanged(object sender, ScrollChangedEventArgs e)
        {
            lbShowNumberOverScroll.ScrollToVerticalOffset((sender as ScrollViewer).VerticalOffset);
            lbShowOverPriceTengScroll.ScrollToVerticalOffset((sender as ScrollViewer).VerticalOffset);
            //lbShowOverPriceTodScroll.ScrollToVerticalOffset((sender as ScrollViewer).VerticalOffset);
        }
        #endregion

        #region :: Form Function ::
        private void ClearListboxOver()
        {
            lbShowNumberOver.SelectedIndex = -1;
            lbShowOverPriceTeng.SelectedIndex = -1;
            lbShowOverPriceTod.SelectedIndex = -1;
        }
        private void DeleteListboxOver(int index)
        {
            lbShowNumberOver.Items.RemoveAt(index);
            lbShowOverPriceTeng.Items.RemoveAt(index);
            lbShowOverPriceTod.Items.RemoveAt(index);
            lbShowOverResult.Items.RemoveAt(index);
        }
        private void loadOverShow()
        {

            if (txtOverNumber.Text.Trim() != string.Empty)
            {
                ListBoxModel temp = new ListBoxModel();
                temp.ID = lbShowNumberOver.Items.Count + 1;
                temp.Value = txtOverNumber.Text;
                lbShowNumberOver_dataSource.Add(temp);

                lbShowNumberOver.ItemsSource = lbShowNumberOver_dataSource.OrderByDescending(s => s.ID).ToList();
            }
            //lbShowOverPriceTeng.Items.Insert(0, txtOverPriceTeng.Text);
            //lbShowOverPriceTod.Items.Insert(0, txtOverPriceTod.Text);

            if (txtOverPriceTeng.Text != "" && txtOverPriceTod.Text == "")
            {
                ListBoxModel temp = new ListBoxModel();
                temp.ID = lbShowOverPriceTeng.Items.Count + 1;
                temp.Value = Decimal.Parse(txtOverPriceTeng.Text).ToString();
                lbShowOverPriceTeng_dataSource.Add(temp);

                lbShowOverPriceTeng.ItemsSource = lbShowOverPriceTeng_dataSource.OrderByDescending(s => s.ID).ToList();

                temp = new ListBoxModel();
                temp.ID = lbShowOverPriceTeng.Items.Count + 1;
                temp.Value = "0";
                lbShowOverPriceTod_dataSource.Add(temp);

                lbShowOverPriceTod.ItemsSource = lbShowOverPriceTod_dataSource.OrderByDescending(s => s.ID).ToList();
            }
            else if (txtOverPriceTeng.Text == "" && txtOverPriceTod.Text != "")
            {
                ListBoxModel temp = new ListBoxModel();
                temp.ID = lbShowOverPriceTeng.Items.Count + 1;
                temp.Value = "0";
                lbShowOverPriceTeng_dataSource.Add(temp);

                lbShowOverPriceTeng.ItemsSource = lbShowOverPriceTeng_dataSource.OrderByDescending(s => s.ID).ToList();

                temp = new ListBoxModel();
                temp.ID = lbShowOverPriceTeng.Items.Count + 1;
                temp.Value = Decimal.Parse(txtOverPriceTod.Text).ToString();
                lbShowOverPriceTod_dataSource.Add(temp);

                lbShowOverPriceTod.ItemsSource = lbShowOverPriceTod_dataSource.OrderByDescending(s => s.ID).ToList();
            }
            else if (txtOverPriceTeng.Text != "" && txtOverPriceTod.Text != "")
            {


                ListBoxModel temp = new ListBoxModel();
                temp.ID = lbShowOverPriceTeng.Items.Count + 1;
                temp.Value = Decimal.Parse(txtOverPriceTeng.Text).ToString();
                lbShowOverPriceTeng_dataSource.Add(temp);

                lbShowOverPriceTeng.ItemsSource = lbShowOverPriceTeng_dataSource.OrderByDescending(s => s.ID).ToList();

                temp = new ListBoxModel();
                temp.ID = lbShowOverPriceTeng.Items.Count + 1;
                temp.Value = Decimal.Parse(txtOverPriceTod.Text).ToString();
                lbShowOverPriceTod_dataSource.Add(temp);

                lbShowOverPriceTod.ItemsSource = lbShowOverPriceTod_dataSource.OrderByDescending(s => s.ID).ToList();
            }
            //lbShowOverResult.Items.Insert(0,);
        }
        private void loadUnderShow()
        {
            lbShowUnderNumber_dataSource.Add(new ListBoxModel() { ID = lbShowUnderNumber.Items.Count + 1, Value = txtUnderNumber.Text });
            lbShowUnderNumber.ItemsSource = lbShowUnderNumber_dataSource.OrderByDescending(s => s.ID).ToList();


            lbShowUnderPrice_dataSource.Add(new ListBoxModel() { ID = lbShowUnderPrice.Items.Count + 1, Value = Decimal.Parse(txtUnderPrice.Text).ToString() });
            lbShowUnderPrice.ItemsSource = lbShowUnderPrice_dataSource.OrderByDescending(s => s.ID).ToList();


        }
        public void clearText()
        {

            txtOverPriceTeng.Text = string.Empty;
            txtOverPriceTod.Text = string.Empty;
            txtOverNumber.Text = string.Empty;
            txtOverNumber.Focus();
            txtOverNumber.SelectAll();
        }

        public void txtOverNumber_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            TextBox tx = sender as TextBox;
            txtOverPriceTeng.Text = string.Empty;
            txtOverPriceTod.Text = string.Empty;
            //txtOverNumber.Text = string.Empty;
            tx.Focus();
            tx.SelectAll();
            // System.Media.SystemSounds.Hand.Play();
            e.Handled = true;
        }
        public void txtOverNumber_MouseLeftButtonUp()
        {
            txtOverPriceTeng.Text = string.Empty;
            txtOverPriceTod.Text = string.Empty;
            txtOverNumber.Focus();
            txtOverNumber.SelectAll();
        }

        public void cleatTextUnder()
        {

            txtUnderNumber.Text = string.Empty;
            txtUnderPrice.Text = string.Empty;
            txtUnderNumber.Focus();
            txtUnderNumber.SelectAll();
        }

        public void txtUnderNumber_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            TextBox tx = sender as TextBox;
            txtUnderPrice.Text = string.Empty;
            tx.Focus();
            tx.SelectAll();
            //System.Media.SystemSounds.Hand.Play();
            e.Handled = true;
        }

        public void txtUnderNumber_MouseLeftButtonUp()
        {
            txtUnderPrice.Text = string.Empty;
            txtUnderNumber.Focus();
            txtUnderNumber.SelectAll();
        }
        private decimal GetNumberShow()
        {
            //List<ShowNumberDTO> show;
            List<ShowNumberDTO> show_3Over;
            List<ShowNumberDTO> show_Tod3Over;
            List<ShowNumberDTO> show_3Under;
            List<ShowNumberDTO> show_2Over;
            List<ShowNumberDTO> show_2Under;
            List<ShowNumberDTO> show_Tod2Over;
            List<ShowNumberDTO> show_TwinFront;
            List<ShowNumberDTO> show_TwinStretch;

            List<NumberDTO> dbNUmber = new List<NumberDTO>();

            decimal t1 = 0;

            dbNUmber = Numberservice.get_numberShow(EnumLocal.NumberType.Over3);
            show_3Over = Gobalsource.ConvetNumberShow(dbNUmber, EnumLocal.NumberConvertShow.Over, 0, 0, 0);
            lblShow_3Over.Content = String.Format("{0:#,##0}", show_3Over.Sum(s => s.Price));

            dbNUmber = Numberservice.get_numberShow(EnumLocal.NumberType.Tod3);
            show_Tod3Over = Gobalsource.ConvetNumberShow(dbNUmber, EnumLocal.NumberConvertShow.Tod, 0, 0, 0);
            lblShow_Tod3Over.Content = String.Format("{0:#,##0}", show_Tod3Over.Sum(s => s.Price));

            dbNUmber = Numberservice.get_numberShow(EnumLocal.NumberType.Under3);
            show_3Under = Gobalsource.ConvetNumberShow(dbNUmber, EnumLocal.NumberConvertShow.Under, 0, 0, 0);
            lblShow_3Under.Content = String.Format("{0:#,##0}", show_3Under.Sum(s => s.Price));

            dbNUmber = Numberservice.get_numberShow(EnumLocal.NumberType.Over2);
            show_2Over = Gobalsource.ConvetNumberShow(dbNUmber, EnumLocal.NumberConvertShow.Over, 0, 0, 0);
            lblShow_2Over.Content = String.Format("{0:#,##0}", show_2Over.Sum(s => s.Price));

            dbNUmber = Numberservice.get_numberShow(EnumLocal.NumberType.Under2);
            show_2Under = Gobalsource.ConvetNumberShow(dbNUmber, EnumLocal.NumberConvertShow.Under, 0, 0, 0);
            lblShow_2Under.Content = String.Format("{0:#,##0}", show_2Under.Sum(s => s.Price));

            dbNUmber = Numberservice.get_numberShow(EnumLocal.NumberType.Tod2);
            show_Tod2Over = Gobalsource.ConvetNumberShow(dbNUmber, EnumLocal.NumberConvertShow.Tod, 0, 0, 0);
            lblShow_Tod2Over.Content = String.Format("{0:#,##0}", show_Tod2Over.Sum(s => s.Price));

            dbNUmber = Numberservice.get_numberShow(EnumLocal.NumberType.TwinFront);
            show_TwinFront = Gobalsource.ConvetNumberShow(dbNUmber, EnumLocal.NumberConvertShow.Over, 0, 0, 0);
            lblShow_TwinFront.Content = String.Format("{0:#,##0}", show_TwinFront.Sum(s => s.Price));

            dbNUmber = Numberservice.get_numberShow(EnumLocal.NumberType.TwinStretch);
            show_TwinStretch = Gobalsource.ConvetNumberShow(dbNUmber, EnumLocal.NumberConvertShow.Over, 0, 0, 0);
            lblShow_TwinStretch.Content = String.Format("{0:#,##0}", show_TwinStretch.Sum(s => s.Price));

            t1 = show_3Over.Sum(s => s.Price) + show_Tod3Over.Sum(s => s.Price) + show_3Under.Sum(s => s.Price) + show_2Over.Sum(s => s.Price) + show_2Under.Sum(s => s.Price) + show_Tod2Over.Sum(s => s.Price) + show_TwinFront.Sum(s => s.Price) + show_TwinStretch.Sum(s => s.Price);
            return t1;
        }
        private decimal GetViewOver1()
        {
            List<NumberDTO> dbNUmber = new List<NumberDTO>();
            List<ShowNumberDTO> showOver;
            List<ShowNumberDTO> showUnit;
            List<ShowNumberDTO> showDecimal;
            List<ShowNumberDTO> showHundred;


            dbNUmber = Numberservice.get_numberShow(EnumLocal.NumberType.Over1);
            showOver = Gobalsource.ConvetNumberShow(dbNUmber, EnumLocal.NumberConvertShow.Over, 0, 0, 0);

            dbNUmber = Numberservice.get_numberShow(EnumLocal.NumberType.Over1Unit);
            showUnit = Gobalsource.ConvetNumberShow(dbNUmber, EnumLocal.NumberConvertShow.Over, 0, 0, 0);

            dbNUmber = Numberservice.get_numberShow(EnumLocal.NumberType.Over1Decimal);
            showDecimal = Gobalsource.ConvetNumberShow(dbNUmber, EnumLocal.NumberConvertShow.Over, 0, 0, 0);

            dbNUmber = Numberservice.get_numberShow(EnumLocal.NumberType.Over1Hundred);
            showHundred = Gobalsource.ConvetNumberShow(dbNUmber, EnumLocal.NumberConvertShow.Over, 0, 0, 0);
            decimal result = showOver.Sum(s => s.Price) + showUnit.Sum(s => s.Price) + showDecimal.Sum(s => s.Price) + showHundred.Sum(s => s.Price);
            lblShow_RunOver.Content = String.Format("{0:#,##0}", result);
            return result;

        }
        private decimal GetViewUnder1()
        {
            List<ShowNumberDTO> show;
            List<ShowNumberDTO> show1;
            List<ShowNumberDTO> show2;

            List<NumberDTO> dbNUmber = new List<NumberDTO>();

            dbNUmber = Numberservice.get_numberShow(EnumLocal.NumberType.Under1);
            //dbNUmber = Gobalsource.GenDummy_1Runing(dbNUmber, EnumLocal.NumberType.Under1);
            show = Gobalsource.ConvetNumberShow(dbNUmber, EnumLocal.NumberConvertShow.Under, 0, 0, 0);

            dbNUmber = Numberservice.get_numberShow(EnumLocal.NumberType.Under1Decimal);
            //dbNUmber = Gobalsource.GenDummy_1Runing(dbNUmber, EnumLocal.NumberType.Under1Decimal);
            show1 = Gobalsource.ConvetNumberShow(dbNUmber, EnumLocal.NumberConvertShow.Under, 0, 0, 0);

            dbNUmber = Numberservice.get_numberShow(EnumLocal.NumberType.Under1unit);
            //dbNUmber = Gobalsource.GenDummy_1Runing(dbNUmber, EnumLocal.NumberType.Under1unit);
            show2 = Gobalsource.ConvetNumberShow(dbNUmber, EnumLocal.NumberConvertShow.Under, 0, 0, 0);
            decimal result = show.Sum(s => s.Price) + show1.Sum(s => s.Price) + show2.Sum(s => s.Price);
            lblShow_RunUnder.Content = String.Format("{0:#,##0}", result);

            return result;

        }
        private decimal GetViewTodGroup()
        {
            // List<ShowNumberDTO> show4;
            List<ShowNumberDTO> show5;
            List<NumberDTO> dbNUmber = new List<NumberDTO>();
            decimal total2;

            // dbNUmber = Numberservice.get_numberShow(EnumLocal.NumberType.FourNumber);
            // show4 = Gobalsource.ConvetNumberShow(dbNUmber, EnumLocal.NumberConvertShow.Tod, 0, 0, 0);

            dbNUmber = Numberservice.get_numberShow(EnumLocal.NumberType.FiveNumber);
            show5 = Gobalsource.ConvetNumberShow(dbNUmber, EnumLocal.NumberConvertShow.Tod, 0, 0, 0);

            lblShow_TodGroup.Content = String.Format("{0:#,##0}", show5.Sum(s => s.Price));
            //  lblShow_4P.Content = String.Format("{0:#,##0}", show4.Sum(s => s.Price));

            //total2 = show4.Sum(s => s.Price) + show5.Sum(s => s.Price);
            total2 = show5.Sum(s => s.Price);
            return total2;
        }
        public void UpdateData()
        {
            newLoadClientMain();
        }
        public void ReloadSceen()
        {

            try
            {
                lblTotal.Content = String.Format("{0:#,##0}", GetNumberShow() + GetViewTodGroup());

            }
            catch (Exception)
            {


            }
        }
        private void DeleteNumber()
        {
            tbl_NumberServer objTblNum = new tbl_NumberServer();
            decimal OverPrice;
            decimal UnderPrice;
            decimal TodPrice;
            string number;
            if (lbShowNumberOver.SelectedIndex > -1)
            {
                number = (lbShowNumberOver.SelectedValue as ListBoxModel).Value;
                OverPrice = Gobalsource.utility.ConvertToDecimal((lbShowOverPriceTeng.SelectedValue as ListBoxModel).Value);
                TodPrice = Gobalsource.utility.ConvertToDecimal((lbShowOverPriceTod.SelectedValue as ListBoxModel).Value);
                //Remove Over
                objTblNum.DeleteNumber(number, OverPrice, 0, TodPrice, BL.Enum.NumberType.NumberOverAdd, Gobalsource.UserNameLogin);

                lbShowNumberOver_dataSource.Remove(lbShowNumberOver.SelectedItem as ListBoxModel);
                lbShowOverPriceTeng_dataSource.Remove(lbShowOverPriceTeng.SelectedItem as ListBoxModel);
                lbShowOverPriceTod_dataSource.Remove(lbShowOverPriceTod.SelectedItem as ListBoxModel);
                lbShowOverResult_dataSource.Remove(lbShowOverResult.SelectedItem as ListBoxModel);

                lbShowNumberOver.ItemsSource = lbShowNumberOver_dataSource.OrderByDescending(s => s.ID).ToList();
                lbShowOverPriceTeng.ItemsSource = lbShowOverPriceTeng_dataSource.OrderByDescending(s => s.ID).ToList();
                lbShowOverPriceTod.ItemsSource = lbShowOverPriceTod_dataSource.OrderByDescending(s => s.ID).ToList();
                lbShowOverResult.ItemsSource = lbShowOverResult_dataSource.OrderByDescending(s => s.ID).ToList();

                lbShowNumberOver.SelectedIndex = -1;
                lbShowOverPriceTeng.SelectedIndex = -1;
                lbShowOverPriceTod.SelectedIndex = -1;
                lbShowOverResult.SelectedIndex = -1;
            }
            else if (lbShowUnderNumber.SelectedIndex > -1)
            {
                number = (lbShowUnderNumber.SelectedValue as ListBoxModel).Value;
                UnderPrice = Gobalsource.utility.ConvertToDecimal((lbShowUnderPrice.SelectedValue as ListBoxModel).Value);
                //Remove Under
                objTblNum.DeleteNumber(number, 0, UnderPrice, 0, BL.Enum.NumberType.NumberUnderAdd, Gobalsource.UserNameLogin);

                lbShowUnderPrice_dataSource.Remove(lbShowUnderPrice.SelectedItem as ListBoxModel);
                lbShowUnderNumber_dataSource.Remove(lbShowUnderNumber.SelectedItem as ListBoxModel);
                lbShowUnderResult_dataSource.Remove(lbShowUnderResult.SelectedItem as ListBoxModel);

                lbShowUnderNumber.ItemsSource = lbShowUnderNumber_dataSource.OrderByDescending(s => s.ID).ToList();
                lbShowUnderPrice.ItemsSource = lbShowUnderPrice_dataSource.OrderByDescending(s => s.ID).ToList();
                lbShowUnderResult.ItemsSource = lbShowUnderResult_dataSource.OrderByDescending(s => s.ID).ToList();

                lbShowUnderNumber.SelectedIndex = -1;
                lbShowUnderPrice.SelectedIndex = -1;
                lbShowUnderResult.SelectedIndex = -1;
            }
            loadOverShow();
            GetViewOver1();
            GetViewUnder1();
            this.ReloadSceen();
        }
        //public void txtFocus()
        //{
        //    txtOverNumber.SelectAll();
        //    txtOverPriceTeng.
        //}
        #endregion
    }
}
